本次主題是以colab的環境進行學習的,在本篇文章中,我將講解影像辨識的基礎技能在接下來的文章中這些技能將多次出現,先讀過這些語法再繼續去看後面的文章會比較能快速上手喔。依照進度每個禮拜都會記錄不同的影像辨識方法,基本順序會從:
載入雲端硬碟:
from google.colab import drive
drive.mount('/content/drive')
下載mediapipe:
!pip install mediapipe
讀入照片及辨識:
import cv2 as cv
import mediapipe as med
import matplotlib.pyplot as plt
dr = med.solutions.drawing_utils
dr_sty = med.solutions.drawing_styles
hand = med.solutions.hands
cap = cv.imread('/content/drive/MyDrive/hand/image.jpg')
img = cap
with hand.Hands(
model_complexity=0,
min_detection_confidence=0.5,
min_tracking_confidence=0.5) as hands:
img2 = cv.cvtColor(img, cv.COLOR_BGR2RGB)
results = hands.process(img2)
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
dr.draw_landmarks(
img,
hand_landmarks,
hand.HAND_CONNECTIONS,
dr_sty.get_default_hand_landmarks_style(),
dr_sty.get_default_hand_connections_style())
img = cv.cvtColor(img,cv.COLOR_BGR2RGB)
plt.imshow(img,cmap="gray")
plt.show()
原始圖片:
實際預測結果:
文章主題一覽:
粗體字為額外更新的文章。